import { sourceUrl } from '@/config';
import { Image, View } from '@tarojs/components';
import React from 'react';

const BackgroundType = {
  color: 1,
  img: 2,
};

const GiftCardBackground = ({ className, backgroundContent, backgroundType }) => {
  if (backgroundType === BackgroundType.color) {
    return <View className={className} style={{ backgroundColor: backgroundContent }}></View>;
  }

  if (backgroundType === BackgroundType.img) {
    const imgSrc =
      backgroundContent.indexOf('http') === 0 ? backgroundContent : sourceUrl + backgroundContent;

    return <Image className={className} src={imgSrc} />;
  }

  return <View className={className}></View>;
};

export default GiftCardBackground;
